﻿<%@ Page Language="C#" Theme="Register" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Web.Security" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = Resources.faContent.fPasswordPageTitle;
        lHelp.Text = Resources.faContent.fPasswordHelpMsg;
        lEmail.Text = Resources.faContent.fPasswordEmailText;
        Btn11.Text = Resources.faContent.fPasswordButtonText;
        rq1.ErrorMessage = Resources.faContent.errorMessageEmailEmpty;
        rqx1.ErrorMessage = Resources.faContent.errorMessageEmailNotValid;
        lHeaderText.Text = Resources.faContent.fPasswrodHeaderText;
           
    }
    
    MembershipUser user;
    protected void Btn1_OnClick(object sender, EventArgs e)
    {
        try
        {
            if (Membership.FindUsersByEmail(EmailAddressTXT.Text).Count > 0)
            {
                user = Membership.GetUser(EmailAddressTXT.Text);
                StreamReader sreader = new StreamReader(Server.MapPath("~") + Resources.global.EmailsFilesRoot + "forgottenPassword.htm");
                string content = sreader.ReadToEnd();
                content = content.Replace("{Username}", EmailAddressTXT.Text);
                content = content.Replace("{Password}", user.ResetPassword());
                SendEmail.EmailActivation(EmailAddressTXT.Text, content, Resources.global.ForgottenPassSubject, Resources.global.SMTP, Resources.global.EmailPass, Resources.global.EmailAddress);
                Message.ForeColor = System.Drawing.Color.Green;
                Message.Text = Resources.faContent.fPasswordSuccessMsg;
                sreader.Close();
                sreader.Dispose();
            }
            else
            {
                Message.ForeColor = System.Drawing.Color.Red;
                Message.Text = Resources.faContent.fPasswordFailMsg; ;
            }
        }
        catch (Exception ex)
        {
            Evoucher.Business.Logging.Logger.LogEvent(ex.ToString(), String.Empty);
            Message.ForeColor = System.Drawing.Color.Red;
            Message.Text = Resources.faContent.fPasswordFailSystemMsg;
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body >
    <form id="form1" runat="server">
    <div class="box" style="width:500px;direction:rtl" >
   <b class="top">
    <b class="bb1 blue"></b>
    <b class="b2 blue"></b>
    <b class="b3 blue"></b>
    <b class="b4 blue"></b>
   </b>
   <div class="con2" >
      <div class="tophead">
       <span >
        <asp:Literal runat="server" ID="lHeaderText" />
       </span>
      </div>
      <div class="con3">
     <span>
      <img src="App_Themes/Admin/images/icon_info.png" alt="" />
      <asp:Literal runat="server" ID="lHelp" /> 
     </span>
     <table >
      <tr>
       <td class="font">
          <asp:Literal runat="server" ID="lEmail" />
       </td>
       <td>
          <asp:TextBox runat="server" ValidationGroup="Register" style="width:220px;border:solid 1px #7DB5DF;" CssClass="ltr"   ID="EmailAddressTXT" MaxLength="70"  />
          <asp:RequiredFieldValidator ValidationGroup="Register"  ID="rq1" runat="server" Display="Dynamic"  ControlToValidate="EmailAddressTXT"  >*</asp:RequiredFieldValidator>
          <asp:RegularExpressionValidator ValidationGroup="Register"  ID="rqx1" runat="server" Display="Dynamic"  ControlToValidate="EmailAddressTXT" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
       </td>
       <td>
        <img src="App_Themes/Register/Images/password.png" alt="" />
       </td>
      </tr>
     </table>
       <center>
        <asp:Button CssClass="submitbutton"  OnClick="Btn1_OnClick"   ValidationGroup="Register" runat="server" ID="Btn11"   />
       </center>            
       <asp:ValidationSummary runat="server" ID="VS" DisplayMode="List" ShowSummary="false" ValidationGroup="Register" EnableClientScript="true" ShowMessageBox="true" />
      </div>
      <center>
      <asp:Label CssClass="font2"  runat="server" ID="Message" />
      </center>
        <br /><br />
   </div>
   <b class="bottom2">
    <b class="b4 blue1"></b>
    <b class="b3 blue1"></b>
    <b class="b2 blue1"></b>
    <b class="bb1 blue1">
    </b>
   </b>
   </div>
    </form>
</body>
</html>
